package com.qf.service.impl;

import com.qf.dao.UserDao;
import com.qf.entity.User;
import com.qf.service.UserService;
import com.qf.util.EncryptUtils;

/**
 * @author zdl
 * @date 2025/1/19
 */
public class UserServiceImpl implements UserService {
    private UserDao userDao = new UserDao();
    @Override
    public User login(String name, String password) {
        User user = loginUser(name, password);
        if (user == null){
            throw new RuntimeException("账户或密码错误");
        }
        if (user.getState() == 2){
            throw  new RuntimeException("该用户已被封禁");
        }
        return user;
    }

    public User loginUser(String name, String password){
        return userDao.selectUserByUserNameAndPassword(name, EncryptUtils.MD5Encode(password));
    }
}
